define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xiservice/refund/index' + location.search,
                    add_url: 'xiservice/refund/add',
                    edit_url: 'xiservice/refund/edit',
                    del_url: 'xiservice/refund/del',
                    multi_url: 'xiservice/refund/multi',
                    import_url: 'xiservice/refund/import',
                    table: 'xiservice_order_refund',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,     
                showExport: false,
                showToggle: false,
                showColumns: false,    
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        {field: 'service.name', title: __('Service.name'), operate: 'LIKE'},
                        {field: 'service.image', title: __('Service.image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},                       
                        {field: 'refund_money', title: __('Refund_money'), operate: false},
                        {field: 'refund_reason', title: __('Refund_reason'), operate:  false},
                        {field: 'refund_images', title: __('Refund_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'content', title: __('Content'), operate: 'LIKE'},
                        {field: 'status', title: __('Stauts'), searchList: {"0":__('Stauts 0'),"1":__('Stauts 1'),"2":__('Stauts 2'),"3":__('Stauts 3')}, formatter: Table.api.formatter.normal},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    text: __('同意'),
                                    title: __('同意'),
                                    confirm: '是否同意退款?',
                                    classname: 'btn btn-xs btn-warning  btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'xiservice/refund/agree?ids={id}',
                                    refresh:true,
                                    visible:function(row){
                                         if(row.status==0){
                                            return true;
                                         }
                                         return false;
                                    }
                                },
                                {
                                    name: 'addtabs',
                                    text: __('拒绝'),
                                    title: __('拒绝'),
                                    confirm: '是否拒绝退款?',
                                    classname: 'btn btn-xs btn-warning btn-ajax',
                                    icon: 'fa fa-close',
                                    url: 'xiservice/refund/refuse?ids={id}',
                                    refresh:true,
                                    visible:function(row){
                                         if(row.status==0){
                                            return true;
                                         }
                                         return false;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons,
                            operate:false
                        }                       

                       //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
